﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acr.XamForms.UserDialogs;
using SpotOffer.CustomViews;
using SpotOffer.Resource;
using Xamarin.Forms;
using XLabs.Forms.Controls;
using XLabs.Forms.Mvvm;

namespace SpotOffer.View
{
    public class DealPage : BasePage
    {
       public   DealPage()
       {
           DependencyService.Get<IUserDialogService>().ShowLoading(AppResources.Loading);

           var webView = new HybridWebView
           {
               VerticalOptions = LayoutOptions.FillAndExpand,
               HorizontalOptions = LayoutOptions.FillAndExpand,
               LoadFinished = FinishedLoading
           };
           webView.SetBinding(HybridWebView.SourceProperty, new Binding("Url"));
           webView.BackgroundColor = AppColors.LighterGrey;

           var openDealButton = new AppViews.ButtonSpotOffer
           {
               Text = AppResources.OpenDealExternally
           };
           openDealButton.SetBinding(Button.CommandProperty, new Binding("Open"));

           // Build the page.
           var stackLayout = AppViews.ContentStackLayout();
           stackLayout.Children.Add(webView);
           stackLayout.Children.Add(openDealButton);

           Content = stackLayout;
       }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            SetBinding(TitleProperty, new Binding("DealTitle"));
        }

        private void FinishedLoading(object sender, EventArgs e)
       {
           Debug.WriteLine(sender.ToString());
           DependencyService.Get<IUserDialogService>().HideLoading();
       }
    }
}
